<template>
  <div class="container">
    <h3 class="title">
      <svg-icon icon-class="money" class="title-icon" />收款账号管理
    </h3>
    <el-card>
      <div slot="header">
        <span>收款账号管理</span>
      </div>
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="商户编码">
          <el-input v-model="formInline.no" placeholder="请输入"></el-input>
          <!-- </el-form-item>
        <el-form-item label="账号户名">
          <el-input v-model="formInline.project"
                    placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="账号">
          <el-input v-model="formInline.bankOfAccount"
          placeholder="请输入"></el-input>-->
        </el-form-item>
        <el-form-item label="关联项目">
          <el-select v-model="formInline.projectId" placeholder="请选择">
            <el-option label="请选择" value></el-option>
            <el-option
              :label="item.name"
              :value="item.id"
              v-for="(item, index) in options"
              :key="index"
            ></el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="是否监管户"
                      style="width:200px;">
          <el-select v-model="formInline.project"
                     style="width:80px"
                     placeholder="请选择">
            <el-option label="区域一"
                       value="shanghai"></el-option>
            <el-option label="区域二"
                       value="beijing"></el-option>
          </el-select>
        </el-form-item>-->
        <el-form-item>
          <el-button type="primary" size="small" @click="handleSearch">查询</el-button>
          <el-button type="primary" size="small" @click="update">更新</el-button>
        </el-form-item>
      </el-form>
      <div style="border-top:1px solid #e6ebf5;margin-bottom:10px;">
        <el-table
          :data="tableData"
          height="calc(100vh - 400px)"
          border
          stripe
          v-loading="loading"
          element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading"
          element-loading-background="transparent"
          style="width: 100%;margin-bottom:10px;"
        >
          <el-table-column prop="id" label="序号"></el-table-column>
          <el-table-column prop="no" label="商户编码"></el-table-column>
          <el-table-column prop="bankOfAccount" label="入账银行"></el-table-column>
          <el-table-column prop="projectName" label="关联项目"></el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button type="text" @click="handleDetail(scope.row)">详情</el-button>
              <el-button type="text" @click="edit(scope.row)">编辑</el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="page"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="totalPage"
          style="float: right;"
        ></el-pagination>
      </div>
    </el-card>
  </div>
</template>

<script>
import { getProject, getList, refresh } from "@/api/money";
export default {
  name: "manage",
  data() {
    return {
      loading: false,
      formInline: {
        no: "",
        bankOfAccount: "",
        projectId: "",
        project: ""
      },
      currentPage4: 4,
      tableData: [],
      page: 1,
      pageSize: 10,
      totalPage: 0,
      options: []
    };
  },
  mounted() {
    this.getOptions();
    this.getData();
  },
  methods: {
    update() {
      this.page = 1;
      this.tableData = [];
      this.loading = true;
      refresh().then(res => {
        getList(
          this.formInline.projectId,
          this.formInline.bankOfAccount,
          this.formInline.no,
          this.page,
          this.pageSize
        ).then(res => {
          this.tableData = res.data;
          this.totalPage = res.recordsTotal;
          setTimeout(() => {
            this.loading = false;
          }, 500);
        });
      });
    },
    getData() {
      getList(
        this.formInline.projectId,
        this.formInline.bankOfAccount,
        this.formInline.no,
        this.page,
        this.pageSize
      ).then(res => {
        this.tableData = res.data;
        this.totalPage = res.recordsTotal;
      });
    },
    getOptions() {
      getProject().then(res => {
        this.options = res.data;
      });
    },
    handleDetail(detail) {
      localStorage.detail = JSON.stringify(detail);
      this.$router.push({ path: "/money/detail" });
    },
    edit(item) {
      localStorage.detail = JSON.stringify(item);
      this.$router.push({ path: "/money/edit" });
    },
    handleSearch() {
      this.getData();
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pageSize = val;
      this.getData();
    },
    handleCurrentChange(val) {
      this.pageSize = val;
      this.getData();
    }
  }
};
</script>

<style lang="scss" scoped>
.container {
  padding: 20px;
  background-color: rgb(240, 242, 245);
  position: relative;
  .title {
    font-size: 14px;
    font-weight: 400;
    .title-icon {
      font-size: 14px;
      display: inline-block;
      margin-right: 5px;
    }
  }
  /deep/ .el-card__header {
    border: 0 none;
  }
}
.title-small {
  font-size: 14px;
}

.money {
  color: #409eff;
}
</style>
